Repository navigation
Port the wp/terms-query ability from WordPress/ai PR #1099 - #10
Merged
Merged
Conversation
Faithful port of the read-only terms query ability from WordPress/ai PR #1099 (author @jorgefilipecosta), on this package's Abstract_Core_Ability authoring surface: - `src/Terms/Terms_Query.php` — the three oneOf modes (a term by ID with the optional taxonomy guard, a term by taxonomy + slug, and a filtered collection answered as { terms, total, total_pages }), the PR's schemas, annotations (readonly, closed-world), permission gates, field projection (id always; description/link off by default; parent hierarchical-only), error codes, and REST-mirroring quirks. Name `core/terms-query` is not carried (D5: wp/ tier experimental, D7: no aliases); registration is the Registrar's; text domain default. - Companion support-surface feature `taxonomy_show_in_abilities` (Support/Features) with the package polyfill marking the built-in `category` and `post_tag` through register_taxonomy_args, mirroring the PR's Show_In_Abilities companion. Verified: no currently supported core declares the WP_Taxonomy flag (7.1 stable and 7.2-beta3 both lack it), so the polyfill marks on both environment branches. - Manifest entry `wp/terms-query` (experimental, content category, proposal ai#1099, requires) + tests/Abilities/TermsQueryTest.php (the ported test triad), README/CHANGELOG/KNOWN-ISSUES updates. Co-authored-by: jorgefilipecosta <jorgefilipecosta@users.noreply.github.com>
This was referenced Oct 30, 2026
nikmclaughlin
added a commit
that referenced
this pull request
Oct 30, 2026
…m-delete) from WordPress/ai PR #1103 (#11) * Port the `wp/term-create`, `wp/term-update`, and `wp/term-delete` Abilities from WordPress/ai PR #1103 ## What? Adds the three term write abilities to the package: a faithful port of WordPress/ai PR #1103 ("Add `core/term-create`, `core/term-update`, and `core/term-delete` abilities", author @jorgefilipecosta), incubating under the experimental tier's `wp/` prefix on the shared `content` category and field projection of `wp/terms-query` (PR #10). The PR's `core/term-*` registration names, gating, and unregister-core-copy wiring are not copied; no aliases exist (D7). ## Why? Agents can read terms through abilities (`wp/terms-query`) but not write them. This package ports the three writes so consumers get one canonical copy while the upstream proposal settles. ## How? - **The abilities:** `src/Terms/Abstract_Term_Write.php` (shared base) + `Term_Create.php` / `Term_Update.php` / `Term_Delete.php` mirror the PR's logic — labels, descriptions, schemas, annotations (create POST semantics, update POST with destructive=true idempotent=false, delete DELETE with destructive=true idempotent=true), error codes, and the guard semantics. Create takes a `taxonomy` and a `name`, plus optional `slug`, `description`, and `parent` (hierarchical only); update takes `id` and the values to change; delete takes `id` and `force`, which must be true because terms cannot be trashed (non-forced answers `terms_trash_not_supported`, 501). On update and delete, `taxonomy` is an optional guard. - **The floors:** creating needs `edit_terms` in a hierarchical taxonomy or `assign_terms` in a flat one; updating needs `edit_term`; deleting needs `delete_term`. A missing term, one outside the exposed taxonomies, or one outside the guard is denied like a missing capability — a generic denial through the validated transport, `terms_term_invalid` (404) on a direct call; a malformed `id` or non-string guard fails closed, never cast onto another term. - **The default category is not protected by any code of its own** (as upstream): core's `map_meta_cap()` answers `do_not_allow` for `delete_term` against the term named by the `default_{$taxonomy}` option, and `wp_delete_term()` returns 0 for it — the denial surfaces as the generic transport denial, `terms_cannot_delete` (403) on a direct call, and `terms_cannot_delete` (500) when a filter grants the capability anyway. - **Answers through the query's contract:** written terms return through the `wp/terms-query` projection (`fields` picking the subset, the ID always included, `parent` only for hierarchical taxonomies); a delete returns `{ deleted, previous }`. - **Code sharing (media pattern):** `Terms_Query` is a hand-authored `wp/*` class, so its shared helpers (`fields` projection, term lookup, item schema) are extracted verbatim from this package's PR #10 port with `private` relaxed to `protected`, into `Abstract_Term_Write`; `Terms_Query` itself keeps its byte-stable backport shape (verify:coreify holds). - **Companions:** the taxonomy opt-in machinery the writes ride (`show_in_abilities` on WP_Taxonomy, polyfilled pre-7.2) and the projection both came from PR #10; the writes need nothing beyond riding them. Manifest entries declare the `taxonomy_show_in_abilities` support feature, as the query does. Co-authored-by: jorgefilipecosta <jorgefilipecosta@users.noreply.github.com> * Tests: pin the settings-update unique-list rows to the r65044 coercion contract ## What? A test-only trunk-drift fix for the settings-update suite (no `src/` change). Core r65044 (#14882, #66383) added `WP_Ability::coerce_input()`, which the Abilities API now runs after validation and before the permission check and execute callback. The `uniqueItems` fixture `('1', '01')` — unique as strings, colliding after the cast — is refused by that layer with `ability_invalid_input` before the plugin code runs, so `SettingsUpdateTest::test_a_value_sanitizing_makes_invalid_is_refused`, which pinned the former contract (`settings_invalid_param` from the plugin), failed deterministically against the trunk nightly (CI run 41034270103). ## How? - The colliding row (`test_a_value_sanitizing_makes_invalid_is_refused`) now pins the framework contract where the coercion layer exists (the exact fixture core's own `data_input_coercion_errors` regression test pins): `ability_invalid_input`, no error data (refusal came from the framework, the plugin's execute callback never ran), nothing written. Hosts without the layer (7.1-, the stable matrix job) keep the plugin's `settings_invalid_param` mapping assertions. - A distinct-after-coercion row (`test_a_list_unique_after_coercion_still_updates`) keeps the callback-reachable list coverage: items casting to distinct integers ('1' and '02') pass validation and coercion, and the coerced list is what the answer carries and what gets stored. - The mapping row (`test_the_plugin_sanitize_refusal_maps_to_settings_invalid_param`) covers the plugin's unchanged `settings_invalid_param` semantics (400, the named param, the all-or-nothing order) directly on the plugin's execute path, as the companion read row already does, since `execute()` can no longer reach the callback with the colliding fixture on coercion hosts. - The `su_list_setting` registration the three rows share moved to `register_unique_list_setting()`. Verified: green against the current trunk nightly (post-r65044) and stable (7.1.4), one wp-env at a time; `phpcs` and `phpstan` clean. --------- Co-authored-by: jorgefilipecosta <jorgefilipecosta@users.noreply.github.com>
This was referenced Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Adds
wp/terms-queryto the package: a faithful port of WordPress/ai PR #1099 ("Addcore/terms-queryability", author @jorgefilipecosta), incubating under the experimental tier'swp/prefix (D5; D7: no aliases — upstream'score/terms-queryname is not carried).Why?
Agents can read posts, users, settings, and media — but not taxonomy terms. This port reads categories, tags, and other opted-in taxonomies like the REST terms endpoints do (plan item B6, part 1).
How?
src/Terms/Terms_Query.phponAbstract_Core_Ability: three modes — a term byid(optionally guarded bytaxonomy), a term bytaxonomy+slug, or the terms of onetaxonomyfiltered bysearch,include,exclude,parent,post,hide_empty,orderby,order,page, andper_page, answered as{ terms, total, total_pages }.id,count,description,link,name,slug,taxonomy,parent(hierarchical taxonomies only); the default set omitsdescriptionandlink;idis always returned.show_in_abilities, like post types forcore/content-query. Core 7.2 provides the flag; a package polyfill covers 6.9–7.1 (per thesetting_show_in_abilitiesprecedent) and markscategory+post_tag. The polyfill's readers accept any truthy opt-in value identically to core's bool cast (verified on trunk); noted in KNOWN-ISSUES.searchmatches name and slug only (the REST-mirroring semantics of this WP version), and collection positives for post-boot-registered taxonomies are pinned at registration time (a suite-harness constraint, noted inline).readonly: true(read-only); manifest: tierexperimental,core_since: null,proposal→ the upstream PR, category ported verbatim from the source registration.Use of AI tools
Tool(s): goose (agent). Model(s): provided via the harness. Used for: implementation, tests, and docs. Reviewed and edited by the committer.
Testing Instructions
wp_abilities_api_initcallback:( new WordPress\Abilities\Registrar )->register_all();wp/terms-querywith{ "taxonomy": "category" }(collection,{ terms, total, total_pages }),{ "id": 1 }(single term), and{ "taxonomy": "category", "slug": "uncategorized" }; try thefieldspicker andhide_empty.composer run lint:phpcs && composer run lint:phpstan && composer run verify:manifest && composer run verify:coreify, and the PHPUnit suite on both wp-env environments (trunk + stable, one at a time) pass.Changelog entries
Added (CHANGELOG.md):
wp/terms-query— tierexperimental, faithful port of the terms read ability from WordPress/ai PR #1099 by @jorgefilipecosta: reads categories, tags, and othershow_in_abilitiestaxonomies by id, by taxonomy+slug, or as a filtered paginated collection.Co-authored-by: jorgefilipecosta jorgefilipecosta@users.noreply.github.com